<?php
	cria_variaveis($_POST,$_GET,$_FILES);
?> 
<p class=titulo align=center><?php echo $msg->get('EQNL_MSG_02') ?></p>
<p class=subtitulo align=center><?php echo $msg->get('EQNL_MSG_03a') ?></p>
<p>
<div class="tabbar">
    <ul>
    <li><a href="index.php?inc=eqnl1.php&modo=material"<?php if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "material") echo " class=\"tabact\""; ?>><?php echo $msg->get('Material_Teorico') ?></a></li>
    <li><a href="index.php?inc=eqnl1.php&modo=exemplo"<?php if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "exemplo") echo " class=\"tabact\""; ?>><?php echo $msg->get('Exemplos_Prontos') ?></a></li>
    <li><a href="index.php?inc=eqnl1.php&modo=teclado"<?php if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "teclado") echo " class=\"tabact\""; ?>><?php echo $msg->get('Entrada_Teclado') ?></a></li>
    </ul>
</div>
<div id="cas">
<?php
if (!isset($Calcular))
{
    if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "material")
    {
        require_once("./classes/upload.php");
        $uploads = new Upload();
        $uploads->Lista("reseqnl");
    }
	else if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "exemplo" && !isset($opcao_execucao))
	{ //leitura de dados via banco de dados - modulo de exemplos e exercicios
		include "exibe_prob_eqnl1_xml.php";
	}
	else if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "teclado" || isset($opcao_execucao))
	{
		if (strlen($opcao_execucao)==0)
		{ 
			echo "<form method=post enctype=multipart/form-data action=index.php?inc=eqnl1.php>";
			echo "<p>".$msg->get('EQNL_MSG_41')."<br><br>";
			echo "<input type=radio name=opcao_execucao value=0> ".$msg->get('EQNL_MSG_42')."<br>";
			echo "<input type=radio name=opcao_execucao value=1> ".$msg->get('EQNL_MSG_43')."<br><br>";
			echo "<input type=hidden name=executar value=sim>";
			echo "<input class=button type=submit name=Submit value=".$msg->get('G_MSG_02').">";
			echo "</form>"; 
			echo "<form method=post enctype=multipart/form-data action=index.php?inc=eqnl1.php>";
			echo "<input class=button type=submit name=Submit value=".$msg->get('G_MSG_03').">";
			echo "</form>";
		}
		else if ( ($opcao_execucao==0)and($deg==NULL) )
		{ //entrar com o valor do grau do polinomio no caso polinomial
			echo "<form method=post enctype=multipart/form-data action=index.php?inc=eqnl1.php>";
			echo "<p>".$msg->get('EQNL_MSG_04')."<br>";
			echo "<input type=text size='2' maxlength='2' name=deg value=".$deg."><br><br>";
			echo "<input type=hidden name=opcao_execucao value=0>";
			echo "<input type=hidden name=executar value=sim>";
			echo "<input class=button type=submit name=Submit value=".$msg->get('G_MSG_02').">";
			echo "</form>"; 
			echo "<form method=post enctype=multipart/form-data action=index.php?inc=eqnl1.php>";
			echo "<input class=button type=submit name=Submit value=".$msg->get('G_MSG_03').">";
			echo "</form>";
		}
		else if  (((($opcao_execucao==0)and($coef[1]==NULL))or(($opcao_execucao==1)and($funcao==NULL)))and($error==NULL)and($it==NULL))
		{ //entrar com os coeficientes do polinomio/funcao de entrada e erro relativo e numero de iteracoes
			echo "<form method=post enctype=multipart/form-data action=index.php?inc=eqnl1.php>";
			if ($opcao_execucao == 0)
			{ //para caso polinomial
				echo "<p>".$msg->get('EQNL_MSG_05')."<br>";
				echo "f(x)=";
				for($i=0;$i<$deg;$i++)
				{
					echo "<input type=text size=5 maxlength=5 name=coef[".$i."] value=".$coef[$i]."> x <sup>".($deg-$i)."</sup>+";
				} // end for
				echo "<input type=text size=5 maxlength=5 name=coef[".$deg."] value=".$coef[$deg]."><br><br>";
				echo "<input type=hidden name=opcao_execucao value=0>";
			} //end if
			else if ($opcao_execucao == 1)
			{  //para caso geral
				echo "<a href=javascript:winopen('ajuda/funcoesphp.php')>".$msg->get('G_MSG_29')."</a>";
				echo "<p>";
				echo $msg->get('EQNL_MSG_40')."<br><br>";
				echo "f(x)= <input type=text size=60 maxlength=100 name=funcao value=".$funcao."><br>";
				echo "<br>";
				echo "<input type=hidden name=opcao_execucao value=1>";
			} // end if
			echo "".$msg->get('EQNL_MSG_06')."<br>";
			echo "<input type=text size=9 maxlength=9 name=error value=".$error."><br><br>";
			echo "".$msg->get('EQNL_MSG_07')."<br>";
			echo "<input type=text size=3 maxlength=3 name=it value=".$it."><br><br>";
			echo "<input type=hidden name=deg value=".$deg.">";
			echo "<input type=hidden name=d value=1>";
			echo "<input type=hidden name=executar value=sim>";
			echo "<input class=button type=submit name=Submit value=".$msg->get('G_MSG_02').">";
			echo "</form>"; 
			echo "<form method=post enctype=multipart/form-data action=index.php?inc=eqnl1.php>";
			echo "<input class=button type=submit name=Submit value=".$msg->get('G_MSG_03').">";
			echo "</form>";
		}
		else 
		{
			if (!isset($_POST['Plotar']) && !isset($POST['Calcular']))
            {
			echo "<form method=post name=formeqnl enctype=multipart/form-data action=index.php?inc=eqnl1.php>";
			echo "<p>";
            if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "exemplo")
                verificaBib($xml_file);
            echo "<br>";
			echo $msg->get('EQNL_MSG_08')."<br>";
			echo "f(x)=";
			if ($opcao_execucao == 0)
			{ //imprimir funcao polinomial
				for($i=0;$i<$deg;$i++)
				{
					echo($coef[$i]);
					echo("x<sup>");
					echo($deg-$i);
					echo("</sup>");
					if ($coef[$i+1]>=0)
					{
						echo "+";
					}
				}
				echo($coef[$deg]);
				echo "<br>";
				echo $msg->get('EQNL_MSG_09')." " .($deg). " <br>";
			} // end if opcao_execucao
			else if ($opcao_execucao == 1)
			{  //imprimir funcao qualquer
				echo $funcao;
				echo "<br>";
			} // end if opcao_execucao
			echo $msg->get('EQNL_MSG_10')." " .($error). " <br>";
			echo $msg->get('EQNL_MSG_11')." " .($it). "<br><br>";
			//cria a tabela de enumeracao de razoes do polinomio - **Caso polinomial**
			if ($opcao_execucao == 0)
			{
				$tabela = enumera_raizes($coef,$deg);
				echo "<table border=1 width=600 cellspacing=0>";
				echo "   <th colspan=4>";
				echo "      <p align=center>".$msg->get('EQNL_MSG_12')."</p>";
				echo "   </th>";
				echo "   <tr>";
				echo "       <td> <p align=center> <b>".$msg->get('EQNL_MSG_13')."</b> </p> </td>";
				echo "       <td> <p align=center> <b>".$msg->get('EQNL_MSG_14')."</b> </p> </td>";
				echo "       <td> <p align=center> <b>".$msg->get('EQNL_MSG_15')."</b> </p> </td>";
				echo "       <td> <p align=center> <b>".$msg->get('EQNL_MSG_16')."</b> </p> </td>";
				echo "   </tr>";
				for ($i = 1; $i <= $tabela[0]["positiva"]; $i++)
				{
					echo "<tr>";
					echo "<td>";
					echo "<p align=center>" .($tabela[$i]["positiva"]). "</p>";
					echo "</td>";
					echo "<td>";
					echo "<p align=center>" .($tabela[$i]["negativa"]). "</p>";
					echo "</td>";
					echo "<td>";
					echo "<p align=center>" .($tabela[$i]["complexa"]). "</p>";
					echo "</td>";
					echo "<td>";
					$total = $tabela[$i]["positiva"] + $tabela[$i]["negativa"] + $tabela[$i]["complexa"];
					echo "<p align=center>" .($total). "</p>";
					echo "</td>";
					echo "</tr>";
				} // end for
				echo "</table><br>";
				// define as cotas superior e inferior **Caso polinomial** (Cota de Laguerre-Thibault)
				$absmax=abs($coef[$deg]);
				for ($i=$deg; $i>0;$i--)
				{
					if (abs($coef[$i]) > $absmax)
						$absmax=abs($coef[$i]);
				}
				$cotacalc=1 + ( (1 / abs($coef[0]) )*$absmax);
				$cota_superior=$cotacalc;
				$cota_inferior=-1*$cotacalc;
				echo "<table border=1 width=600 cellspacing=0>";
				echo "   <th colspan=2>";
				echo "      <p align=center>".$msg->get('EQNL_MSG_17')."</p>";
				echo "   </th>";
				//echo "</table>";
				//echo "<table border=1 width=600 cellspacing=0>";
				echo "   <tr>";
				echo "    <td>";
				echo "      <p align=center> <b>".$msg->get('EQNL_MSG_18')."</b> </p>";
				echo "    </td>";
				echo "    <td>";
				echo "      <p align=center> <b>".$msg->get('EQNL_MSG_19')."</b> </p>";
				echo "    </td>";
				echo "   </tr>";
				echo "   <tr>";
				echo "    <td>";
				echo "      <p align=center>" .($cota_inferior). "</p>";
				echo "    </td>";
				echo "    <td>";
				echo "      <p align=center>" .($cota_superior). "</p>";
				echo "    </td>";
				echo "   </tr>";
				echo "</table>";
			} // end if opcao == 0 (polinomial)     
			echo "<br>".$msg->get('Intervalo_Para_Plotar')."<br>";
            echo "[<input type=text size=5 maxlength=5 name=graphx1 value=".@$graphx1."> ; <input type=text size=5 maxlength=5 name=graphx2 value=".@$graphx2."> ]<br><br>";
            echo "<input type=hidden name=x0 value=".@$x0.">";
            echo "<input type=hidden name=x1 value=".@$x1.">";
			echo "<input type=hidden name=executar value=sim>";
			echo "<input type=hidden name=it value=".$it.">";
			echo "<input type=hidden name=error value=".$error.">";
            echo "<input type=hidden name=mudagrafico value=sim>";
			if ($opcao_execucao == 0)
			{
				echo "<input type=hidden name=deg value=".$deg.">";
				echo "<input type=hidden name=d value=".@$d.">";
				for($i=0;$i<$deg;$i++)
				{
				   echo "<input type=hidden name=coef[] value=".$coef[$i].">";
				}
				echo "<input type=hidden name=coef[] value=".$coef[$deg].">";
				echo "<input type=hidden name=opcao_execucao value=0>";
			} // end if opcao_execucao == 0
			if ($opcao_execucao == 1) {
				echo "<input type=hidden name=funcao value=".$funcao.">";
				echo "<input type=hidden name=opcao_execucao value=1>";
			} // end if opcao_execucao == 1
			echo "<p><p>";
			if (@$correcao == "sim") {
				echo "<input type=hidden name=correcao value=sim>";
				echo "<input type=hidden name=resp value=".$resp.">";
				echo "<input type=hidden name=resp_it value=".$resp_it.">";
				echo "<b>".$msg->get('EQNL_MSG_21')."</b>";
				echo "<br>";
				echo $msg->get('EQNL_MSG_22')."".$resp."".$msg->get('EQNL_MSG_23')."".$resp_it."".$msg->get('EQNL_MSG_24');
				echo "<p>";
			} // end if
			echo "<p>";
			if (isset($_POST["navegacao"]) && $_POST["navegacao"] == "sim")
			{
				echo "<input type=\"hidden\" name=\"xml_file\" value=\"".$xml_file."\">";
				echo "<input type=\"hidden\" name=\"indice\" value=\"$indice\">";
				echo "<input type=\"hidden\" name=\"navegacao\" value=\"sim\">";
			}
			echo "<input type=hidden name=metodo value=secante>";
			//echo "<input class=button type=button name=Submit value=".(EQNL_MSG_25)." onClick=\"enviar()\"><br><br>";
			if (isset($_POST["respeqnl2"]))
			{
				echo "<input type=\"hidden\" name=\"respeqnl2\" value=\"".$_POST["respeqnl2"]."\">";
				echo "<input type=\"hidden\" name=\"itereqnl2\" value=\"".$_POST["itereqnl2"]."\">";
			}
			if (isset($_POST["respeqnl3"]))
			{
				echo "<input type=\"hidden\" name=\"respeqnl3\" value=\"".$_POST["respeqnl3"]."\">";
				echo "<input type=\"hidden\" name=\"itereqnl3\" value=\"".$_POST["itereqnl3"]."\">";
			}
			echo "<input class=button type=submit name=Plotar value=".$msg->get('EQNL_MSG_25').">";
			echo "<br>";
			echo "</form>";
	        echo "<form method=post enctype=multipart/form-data action=index.php?inc=eqnl1.php>";
			echo "<input class=button type=submit name=Submit value=".$msg->get('G_MSG_03').">";
			echo "</form>";
			if (isset($_POST["navegacao"]) && $_POST["navegacao"] == "sim")
			{
				echo "<form name=\"exemplos\" enctype=\"multipart/form-data\" method=\"post\">";
				echo "<script language=\"javascript\" type=\"text/javascript\">\n";
				echo "function criarLinks(value) {\n";
				echo "document.exemplos.indice.value = value;\n";
				echo "document.exemplos.action = 'index.php?inc=eqnl1.php&modo=exemplo'\n";
				echo "document.exemplos.submit();\n";
				echo "}\n";
				echo "</script>";
				echo "<input type=\"hidden\" name=\"id_bib\" value=\"".$id_bib."\">";
				echo "<input type=\"hidden\" name=\"xml_file\" value=\"".$xml_file."\">";
				echo "<input type=\"hidden\" name=\"indice\">";
				echo "</form>";
				echo $msg->get('Outros_Exemplos').":<br>";
                $objeto = new DOMDocument();
                $objeto->load($xml_file);
            	$filho = $objeto->getelementsbytagname("rootfinding");
            	if ($filho->length > 0)
            	{
            		$tmp=0;
            		$equation = $filho->item(0)->getelementsbytagname("equation");
            		for ($i = 0; $i < $equation->length; $i++)
            		{
            			$temp=$equation->item($i)->getelementsbytagname("option");
            			$temp1=$temp->item(0)->getattribute("data");
            			if ($temp1 == 'polynom')
            			{
                			$tmp++;
                			if ($i) echo " | ";
                			if ($i == $indice) echo "<b>";
                			echo "<a href=\"javascript:criarLinks($i);\"><u>".($tmp)."</u></a>";
                			if ($i == $indice) echo "</b>";
            			}
            		}
            		for ($i = 0; $i < $equation->length; $i++)
                	{
                        $temp=$equation->item($i)->getelementsbytagname("option");
                        $temp1=$temp->item(0)->getattribute("data");
                        if ($temp1 == 'function')
                        {
                            $tmp++;
                			if ($i) echo " | ";
                   			if ($i == $indice) echo "<b>";
                			echo "<a href=\"javascript:criarLinks($i);\"><u>".($tmp)."</u></a>";
                			if ($i == $indice) echo "</b>";
            			}
               		}
            	}
			}
		} //end if
            else {
                echo "<form method=post name=formeqnl enctype=multipart/form-data action=index.php?inc=eqnl1.php>";
                echo "<p>";
                if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "exemplo")
                    verificaBib($xml_file);
                echo "<br>";
                echo $msg->get('EQNL_MSG_08')."<br>";
                echo "f(x)=";
                if ($opcao_execucao == 0) { //imprimir funcao polinomial
                    for($i = 0; $i < $deg; $i++) {
                        echo $coef[$i]."x<sup>".($deg-$i)."</sup>";
                        if ($coef[$i+1] >= 0)
                            echo "+";
                    }
                    echo($coef[$deg])."<br>".$msg->get('EQNL_MSG_09')." ".($deg)." <br>";
                } // end if opcao_execucao
                else if ($opcao_execucao == 1) { //imprimir funcao qualquer
                    echo $funcao."<br>";
                } // end if opcao_execucao
                echo $msg->get('EQNL_MSG_10')." " .($error). " <br>";
                echo $msg->get('EQNL_MSG_11')." " .($it). "<br><br>";
                $dados_grafico = "$opcao_execucao|";
                if ($opcao_execucao == 0) {
                    $dados_grafico .= "$deg|";
                        for ($i=0;$i<=$deg;$i++) { $dados_grafico .= "$coef[$i]|" ;}
                } // end if
                if ($opcao_execucao == 1) {
                    $aux = normaliza_funcao($funcao);
                    $dados_grafico .= "$aux|";
                } // end if
                $dados_grafico .= "$graphx1|";
                $dados_grafico .= "$graphx2|";
                $arquivo = gera_nome_arquivo();
                $conn = &ADONewConnection($A_DB_TYPE);
                $conn->PConnect($A_DB_HOST,$A_DB_USER,$A_DB_PASS,$A_DB_DB);
                $sql = "INSERT INTO grafico(id,dados) values ('".$arquivo."','".$dados_grafico."');";
                $rs = $conn->Execute($sql);
                if ($rs === false) die(A_LANG_LOGIN_MSG5);
                $rs->Close();
                echo "<br>";
                echo "<table>";
                echo "<tr>";
                echo "<td><img src=eqnl_grafico.php?arquivo=".$arquivo."  border=0 align=center width=600 height= 400></td>";
                echo "</table>";
                echo "<br><br>";

                echo "<br>";
			    echo $msg->get('EQNL_MSG_20a')."<br>";
			    echo "x<sub>0</sub>: <input type=text size=5 maxlength=5 name=x0 value=".(@$x0)."><br>";
			    echo "x<sub>1</sub>: <input type=text size=5 maxlength=5 name=x1 value=".(@$x1).">";
                echo "</font>";
                echo "<input type=hidden name=executar value=sim>";
                echo "<input type=hidden name=it value=".$it.">";
                echo "<input type=hidden name=error value=".$error.">";
                if ($opcao_execucao == 0) {
                    echo "<input type=hidden name=deg value=".$deg.">";
                    echo "<input type=hidden name=d value=".@$d.">";
                    for($i = 0; $i < $deg; $i++) {
                        echo "<input type=hidden name=coef[] value=".$coef[$i].">";
                    }
                    echo "<input type=hidden name=coef[] value=".$coef[$deg].">";
                    echo "<input type=hidden name=opcao_execucao value=0>";
                } // end if opcao_execucao == 0
                if ($opcao_execucao == 1) {
                    echo "<input type=hidden name=funcao value=".$funcao.">";
                    echo "<input type=hidden name=opcao_execucao value=1>";
                } // end if opcao_execucao == 1
                echo "<p><p>";
                echo "<p>";
                if (isset($_POST["navegacao"]) && $_POST["navegacao"] == "sim") {
                    echo "<input type=\"hidden\" name=\"xml_file\" value=\"".$xml_file."\">";
                    echo "<input type=\"hidden\" name=\"indice\" value=\"$indice\">";
                    echo "<input type=\"hidden\" name=\"navegacao\" value=\"sim\">";
                }
                echo "<input type=\"hidden\" name=\"metodo\" value=\"bisseccao\">";
                if (isset($_POST["respeqnl1"])) {
                    echo "<input type=\"hidden\" name=\"respeqnl1\" value=\"".$_POST["respeqnl1"]."\">";
                    echo "<input type=\"hidden\" name=\"itereqnl1\" value=\"".$_POST["itereqnl1"]."\">";
                }
                if (isset($_POST["respeqnl3"])) {
                    echo "<input type=\"hidden\" name=\"respeqnl3\" value=\"".$_POST["respeqnl3"]."\">";
                    echo "<input type=\"hidden\" name=\"itereqnl3\" value=\"".$_POST["itereqnl3"]."\">";
                }
                echo "<input type=hidden name=graphx1 value=".@$graphx1.">";
                echo "<input type=hidden name=graphx2 value=".@$graphx2.">";
                echo "<input class=button type=submit name=Calcular value=".$msg->get('G_MSG_04').">";
                if (isset($_POST['mudagrafico']))
                {
                    echo "<br><br><br>Plotar o grafico em outro intervalo:<br>";
                    echo "[<input type=text size=5 maxlength=5 name=graphx1 value=".@$graphx1."> ; <input type=text size=5 maxlength=5 name=graphx2 value=".@$graphx2."> ]<br><br>";
                    echo "<input type=hidden name=mudagrafico value=sim>";
                    echo "<input class=button type=submit name=Plotar value=".$msg->get('EQNL_MSG_25').">";
                }
                echo "<br>";
                echo "<form method=post enctype=multipart/form-data action=index.php?inc=eqnl2.php>";
                echo "<input class=button type=submit name=Submit value=".$msg->get('G_MSG_03').">";
                echo "</form>";
                if (isset($_POST["navegacao"]) && $_POST["navegacao"] == "sim") {
                    echo "<form name=\"exemplos\" enctype=\"multipart/form-data\" method=\"post\">";
                    echo "<script language=\"javascript\" type=\"text/javascript\">\n";
                    echo "function criarLinks(value) {\n";
                    echo "document.exemplos.indice.value = value;\n";
                    echo "document.exemplos.action = 'index.php?inc=eqnl2.php&modo=exemplo'\n";
                    echo "document.exemplos.submit();\n";
                    echo "}\n";
                    echo "</script>";
                    echo "<input type=\"hidden\" name=\"id_bib\" value=\"".$id_bib."\">";
                    echo "<input type=\"hidden\" name=\"xml_file\" value=\"".$xml_file."\">";
                    echo "<input type=\"hidden\" name=\"indice\">";
                    echo "</form>";
                    echo $msg->get('Outros_Exemplos').":<br>";
                    $objeto = new DOMDocument();
                    $objeto->load($xml_file);
                    $filho = $objeto->getelementsbytagname("rootfinding");
                    if ($filho->length > 0)
                    {
                        $tmp=0;
                        $equation = $filho->item(0)->getelementsbytagname("equation");
                        for ($i = 0; $i < $equation->length; $i++)
                        {
                            $temp=$equation->item($i)->getelementsbytagname("option");
                            $temp1=$temp->item(0)->getattribute("data");
                            if ($temp1 == 'polynom')
                            {
                                $tmp++;
                                if ($i) echo " | ";
                                if ($i == $indice) echo "<b>";
                                echo "<a href=\"javascript:criarLinks($i);\"><u>".($tmp)."</u></a>";
                                if ($i == $indice) echo "</b>";
                            }
                        }
                        for ($i = 0; $i < $equation->length; $i++)
                        {
                            $temp=$equation->item($i)->getelementsbytagname("option");
                            $temp1=$temp->item(0)->getattribute("data");
                            if ($temp1 == 'function')
                            {
                                $tmp++;
                                if ($i) echo " | ";
                                if ($i == $indice) echo "<b>";
                                echo "<a href=\"javascript:criarLinks($i);\"><u>".($tmp)."</u></a>";
                                if ($i == $indice) echo "</b>";
                            }
                        }
                    }
                }
            }
		echo "</body>";
        }
	}
}
else
{
    if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "exemplo")
        verificaBib($xml_file);
    echo "<br>";
	echo $msg->get('EQNL_MSG_08')."<br>";
	echo "f(x)=";
	if ($opcao_execucao == 0)
	{ //imprimir funcao polinomial
		for($i=0;$i<$deg;$i++)
		{
			echo($coef[$i]);
			echo("x<sup>");
			echo($deg-$i);
			echo("</sup>");
			if ($coef[$i+1]>=0)
			{
				echo "+";
			}
		}
		echo($coef[$deg]);
		echo "<br>";
		echo $msg->get('EQNL_MSG_09')."".($deg)."<br>";
	} // end if opcao_execucao
	else if ($opcao_execucao == 1)
	{  //imprimir funcao qualquer
		echo $funcao;
		echo "<br>";
	} // end if opcao_execucao
	echo $msg->get('EQNL_MSG_10')."" .($error)."<br>";
	echo $msg->get('EQNL_MSG_11')."".($it)."<br>";
	echo $msg->get('EQNL_MSG_26a')."<br>";
	echo "x<sub>0</sub>= ".($x0)."<br>";
	echo "x<sub>1</sub>= ".($x1)."<br>";
	echo "<table border=1 width=30% cellspacing=0>";
	echo "   <tr>";
	echo "    <td>";
	echo "      <p align=center> <b>".$msg->get('EQNL_MSG_27')."</b> </p>";
	echo "    </td>";
	echo "    <td>";
	echo "      <p align=center> <b> x </b> </p>";
	echo "    </td>";
	echo "    <td>";
	echo "      <p align=center> <b> f(x) </b> </p>";
	echo "    </td>";
	echo "    <td>";
	echo "      <p align=center> <b> ".$msg->get("Erro_Relativo")." </b> </p>";
	echo "    </td>";
	echo "   </tr>";
	$j=0;
	$stop=false;
	while(($j<=$it)&&($stop!=true))
	{
		$j++;
		if ($opcao_execucao == 0)
		{
			$resx1=Resolve($coef,$deg,$x1);
			$resx0=Resolve($coef,$deg,$x0);
		} // end if
		else if ($opcao_execucao == 1)
		{
			$auxfunc = normaliza_funcao($funcao).";";
			$x=$x1;
			eval('$resx1='.$auxfunc);
			$x=$x0;
			eval('$resx0='.$auxfunc);
		} // end else
		$den=(float)($resx1-$resx0);
		if(abs($den)>=$error)
		{
			$x2=$x1-($resx1*($x1-$x0))/$den;
			$aux=max(1,abs($x2));
			$localerror=abs($x2-$x1)/abs($aux);
			$resx2=0;
			if ($opcao_execucao == 0)
			{
				for($i=0;$i<$deg;$i++)
				{
					$resx2=$resx2+$coef[$i]*potencia( $x1, $deg- $i);
				}
				$resx2=$resx2+$coef[$deg];
			}
			else if ($opcao_execucao == 1)
			{
				$x = $x1;
				eval('$resx2='.$auxfunc);
			}
			//imprimir as iteracoes na tela
			if ($j != 1)
			{
				echo "   <tr>";
				echo "    <td>";
				echo "      <p align=center>" .($j-1). "</p>";
				echo "    </td>";
				echo "    <td>";
				echo "      <p align=center>" .($x2). "</p>";
				echo "    </td>";
				echo "    <td>";
				echo "      <p align=center>" .($resx2). "</p>";
				echo "    </td>";
				echo "    <td>";
				echo "      <p align=center>" .(($j!=2)?($localerror):'-'). "</p>";
				echo "    </td>";
				echo "   </tr>";
			}
			if($localerror<$error)
			{
				echo "</table>";
				echo "<br><b>".$msg->get('EQNL_MSG_28')."</b><br>";
				$msg2=$msg->get('EQNL_MSG_22')."".$x2."".$msg->get('EQNL_MSG_23')."".($j-1)."".$msg->get('EQNL_MSG_24')."<br>";
				echo $msg2;
				if ($opcao_execucao == 0) verifica_polino($coef,$deg,$x2);
				elseif ($opcao_execucao == 1) verifica_funcao($funcao,$x2);
				$encontrouresp=true;
				$respencontrada=$x2;
				$respiteracoes=$j;
				$stop=true;
                if (isset($_POST["respeqnl2"]) && isset($_POST["respeqnl3"]))
                {
                    echo $_POST["itereqnl1"]."/".$_POST["itereqnl2"]."/".$j;
                    if ($opcao_execucao==0) quadrocomp($x2,$j,$_POST["respeqnl2"],$_POST["itereqnl2"],$_POST["respeqnl3"],$_POST["itereqnl3"],0,$coef,$deg);
                    else  quadrocomp($x2,$j,$_POST["respeqnl2"],$_POST["itereqnl2"],$_POST["respeqnl3"],$_POST["itereqnl3"],1,$funcao);
                }
			}
			if($resx2=0)
			{
				echo "</table>";
				echo "<br><b>".$msg->get('EQNL_MSG_28')."</b><br>";
				$msg2=$msg->get('EQNL_MSG_29')."".$x2."<br>";
				echo $msg2;
				$encontrouresp=true;
				$respencontrada=$x2;
				$respiteracoes=$j;
				$stop=true;
			}
			if(!$stop)
			{
				$x0=$x1;
				$x1=$x2;
			}
		} //end if
		else
		{
			if(($resx0==0)&&($resx1==0))
			{
				echo "</table>";
				$msg2=$msg->get('EQNL_MSG_30');
			}
			else
			{
				echo "</table>";
				$msg2=$msg->get('EQNL_MSG_31')."<br>";
			}
			echo "<br><b>".$msg->get('EQNL_MSG_28')."</b><br>";
			echo $msg2;
			$stop=true;
		} //end else
	} // end while
	if($j>=$it)
	{
		echo "</table>";
		echo "<br> <b>".$msg->get('EQNL_MSG_28')."</b> <br>";
		$msg2=$msg->get('EQNL_MSG_32')."".($j-1)."".$msg->get('EQNL_MSG_33')."<br>";
		echo $msg2;
	}
	echo "<br>";
	echo "<form method=post enctype=multipart/form-data action=index.php?inc=eqnl1.php>";
	if (isset($_POST["navegacao"]) && $_POST["navegacao"] == "sim")
	{
		echo "<input type=\"hidden\" name=\"xml_file\" value=\"".$xml_file."\">";
		echo "<input type=\"hidden\" name=\"indice\" value=\"$indice\">";
		echo "<input type=\"hidden\" name=\"navegacao\" value=\"sim\">";
	}
	if (isset($_POST["respeqnl2"]))
	{
		echo "<input type=\"hidden\" name=\"respeqnl2\" value=\"".$_POST["respeqnl2"]."\">";
		echo "<input type=\"hidden\" name=\"itereqnl2\" value=\"".$_POST["itereqnl2"]."\">";
	}
	if (isset($_POST["respeqnl3"]))
	{
		echo "<input type=\"hidden\" name=\"respeqnl3\" value=\"".$_POST["respeqnl3"]."\">";
		echo "<input type=\"hidden\" name=\"itereqnl3\" value=\"".$_POST["itereqnl3"]."\">";
	}
	echo "<input type=hidden name=executar value=sim>";
	echo "<input type=hidden name=resp value=".@$resp.">";
	echo "<input type=hidden name=correcao value=".@$correcao.">";
	echo "<input type=hidden name=resp_it value=".@$resp_it.">";
	echo "<input type=hidden name=it value=".@$it.">";
	echo "<input type=hidden name=error value=".@$error.">";
	if ($opcao_execucao==0)
	{
		echo "<input type=hidden name=deg value=".$deg.">";
		echo "<input type=hidden name=d value=".$d.">";
		for($i=0;$i<$deg;$i++)
		{
			 echo "<input type=hidden name=coef[".$i."] value=".$coef[$i].">";
		}
		echo "<input type=hidden name=coef[] value=".$coef[$deg].">";
		echo "<input type=hidden name=opcao_execucao value=0>";
	} // end if
	if ($opcao_execucao == 1)
	{
		echo "<input type=hidden name=funcao value=".$funcao.">";
		echo "<input type=hidden name=opcao_execucao value=1>";
	} // end if
    echo "<input type=hidden name=graphx1 value=".@$graphx1.">";
    echo "<input type=hidden name=graphx2 value=".@$graphx2.">";
	echo "<input class=button type=submit name=Plotar value=".$msg->get('EQNL_MSG_35').">";
	echo "</form>";
	echo "<p>";
	echo $msg->get('G_PROXIMO_EXEMPLO')."<p>";
	// formulario para Metodo da Bisseccao
	echo "<form method=post enctype=multipart/form-data action=index.php?inc=eqnl2.php>";
	if (isset($_POST["navegacao"]) && $_POST["navegacao"] == "sim")
	{
		echo "<input type=\"hidden\" name=\"xml_file\" value=\"".$xml_file."\">";
		echo "<input type=\"hidden\" name=\"indice\" value=\"$indice\">";
		echo "<input type=\"hidden\" name=\"navegacao\" value=\"sim\">";
	}
	if (isset($encontrouresp) && $encontrouresp == true)
	{
		echo "<input type=\"hidden\" name=\"respeqnl1\" value=\"$respencontrada\">";
		echo "<input type=\"hidden\" name=\"itereqnl1\" value=\"$respiteracoes\">";
	}
	if (isset($_POST["respeqnl2"]))
	{
		echo "<input type=\"hidden\" name=\"respeqnl2\" value=\"".$_POST["respeqnl2"]."\">";
		echo "<input type=\"hidden\" name=\"itereqnl2\" value=\"".$_POST["itereqnl2"]."\">";
	}
	if (isset($_POST["respeqnl3"]))
	{
		echo "<input type=\"hidden\" name=\"respeqnl3\" value=\"".$_POST["respeqnl3"]."\">";
		echo "<input type=\"hidden\" name=\"itereqnl3\" value=\"".$_POST["itereqnl3"]."\">";
	}
	echo "<input type=hidden name=executar value=sim>";
	echo "<input type=hidden name=resp value=".@$resp.">";
	echo "<input type=hidden name=correcao value=".@$correcao.">";
	echo "<input type=hidden name=resp_it value=".@$resp_it.">";
	echo "<input type=hidden name=it value=".@$it.">";
	echo "<input type=hidden name=error value=".@$error.">";
	if ($opcao_execucao==0)
	{
		echo "<input type=hidden name=deg value=".$deg.">";
		echo "<input type=hidden name=d value=".$d.">";
		for($i=0;$i<$deg;$i++)
		{
			 echo "<input type=hidden name=coef[".$i."] value=".$coef[$i].">";
		}
		echo "<input type=hidden name=coef[] value=".$coef[$deg].">";
		echo "<input type=hidden name=opcao_execucao value=0>";
	} // end if
	if ($opcao_execucao == 1) {
		echo "<input type=hidden name=funcao value=".$funcao.">";
		echo "<input type=hidden name=opcao_execucao value=1>";
	} // end if
	echo "<input class=button type=submit name=Calcular value='".$msg->get('EQNL_MSG_03b')."'>";
	echo "</form>";
	// formulario para Metodo de Newton
	echo "<form method=post enctype=multipart/form-data action=index.php?inc=eqnl3.php>";
	if (isset($_POST["navegacao"]) && $_POST["navegacao"] == "sim")
	{
		echo "<input type=\"hidden\" name=\"xml_file\" value=\"".$xml_file."\">";
		echo "<input type=\"hidden\" name=\"indice\" value=\"$indice\">";
		echo "<input type=\"hidden\" name=\"navegacao\" value=\"sim\">";
	}
	if (isset($encontrouresp) && $encontrouresp == true)
	{
		echo "<input type=\"hidden\" name=\"respeqnl1\" value=\"$respencontrada\">";
		echo "<input type=\"hidden\" name=\"itereqnl1\" value=\"$respiteracoes\">";
	}
	if (isset($_POST["respeqnl2"]))
	{
		echo "<input type=\"hidden\" name=\"respeqnl2\" value=\"".$_POST["respeqnl2"]."\">";
		echo "<input type=\"hidden\" name=\"itereqnl2\" value=\"".$_POST["itereqnl2"]."\">";
	}
	if (isset($_POST["respeqnl3"]))
	{
		echo "<input type=\"hidden\" name=\"respeqnl3\" value=\"".$_POST["respeqnl3"]."\">";
		echo "<input type=\"hidden\" name=\"itereqnl3\" value=\"".$_POST["itereqnl3"]."\">";
	}
	echo "<input type=hidden name=executar value=sim>";
	echo "<input type=hidden name=resp value=".@$resp.">";
	echo "<input type=hidden name=correcao value=".@$correcao.">";
	echo "<input type=hidden name=resp_it value=".@$resp_it.">";
	echo "<input type=hidden name=it value=".@$it.">";
	echo "<input type=hidden name=error value=".@$error.">";
	if ($opcao_execucao==0)
	{
		echo "<input type=hidden name=deg value=".$deg.">";
		echo "<input type=hidden name=d value=".$d.">";
		for($i=0;$i<$deg;$i++)
		{
			 echo "<input type=hidden name=coef[".$i."] value=".$coef[$i].">";
		}
		echo "<input type=hidden name=coef[] value=".$coef[$deg].">";
		echo "<input type=hidden name=opcao_execucao value=0>";
	} // end if
	if ($opcao_execucao == 1) {
		echo "<input type=hidden name=funcao value=".$funcao.">";
		echo "<input type=hidden name=opcao_execucao value=1>";
	} // end if
	echo "<input class=button type=submit name=Submit value='".$msg->get('EQNL_MSG_03c')."'>";
	echo "</form>";
	echo "<form method=post enctype=multipart/form-data action=index.php?inc=eqnl1.php>";
	echo "<input class=button type=submit name=Submit value=".$msg->get('G_MSG_03').">";
	echo "</form>";
	if (isset($_POST["navegacao"]) && $_POST["navegacao"] == "sim")
	{
		echo "<form name=\"exemplos\" enctype=\"multipart/form-data\" method=\"post\">";
		echo "<script language=\"javascript\" type=\"text/javascript\">\n";
		echo "function criarLinks(value) {\n";
		echo "document.exemplos.indice.value = value;\n";
		echo "document.exemplos.action = 'index.php?inc=eqnl1.php&modo=exemplo'\n";
		echo "document.exemplos.submit();\n";
		echo "}\n";
		echo "</script>";
		echo "<input type=\"hidden\" name=\"id_bib\" value=\"".@$id_bib."\">";
		echo "<input type=\"hidden\" name=\"xml_file\" value=\"".@$xml_file."\">";
		echo "<input type=\"hidden\" name=\"indice\">";
		echo "</form>";
		echo $msg->get('Outros_Exemplos').":<br>";
        $objeto = new DOMDocument();
        $objeto->load($xml_file);
    	$filho = $objeto->getelementsbytagname("rootfinding");
    	if ($filho->length > 0)
    	{
    		$tmp=0;
    		$equation = $filho->item(0)->getelementsbytagname("equation");
    		for ($i = 0; $i < $equation->length; $i++)
    		{
    			$temp=$equation->item($i)->getelementsbytagname("option");
    			$temp1=$temp->item(0)->getattribute("data");
    			if ($temp1 == 'polynom')
    			{
                    $tmp++;
                    if ($i) echo " | ";
                    if ($i == $indice) echo "<b>";
                    echo "<a href=\"javascript:criarLinks($i);\"><u>".($tmp)."</u></a>";
                    if ($i == $indice) echo "</b>";
    			}
    		}
    		for ($i = 0; $i < $equation->length; $i++)
    		{
    			$temp=$equation->item($i)->getelementsbytagname("option");
    			$temp1=$temp->item(0)->getattribute("data");
    			if ($temp1 == 'function')
    			{
        			$tmp++;
        			if ($i) echo " | ";
        			if ($i == $indice) echo "<b>";
           			echo "<a href=\"javascript:criarLinks($i);\"><u>".($tmp)."</u></a>";
                    if ($i == $indice) echo "</b>";
       			}
    		}
    	}
	}
}
?>
</div>